<template>
  <div class="table contract">
    <div class="card">
      <div class="card_nav">
        <div>
          <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='TIANJIA'))!==-1" size="small" class="bottom_all" style="margin-left: 0;" @click="addFromDate('添加'),reset()">
            <i class="icon iconfont iconicon_button_add" style="font-size: 12px;"></i>
            添加
          </el-button>
          <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='RIYONG'))!==-1" size="small" class="bottom_three" @click="UpdateOrDelete('update_enable', 1)">
            <i class="icon iconfont iconicon_button_startuse" style="font-size: 12px;"></i>
            启用
          </el-button>
          <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='JINYONG'))!==-1" size="small" class="bottom_four" @click="UpdateOrDelete('update_enable', 0)">
            <i class="icon iconfont iconicon_button_disable1" style="font-size: 12px;"></i>
            禁用
          </el-button>
          <el-button v-if="ButtonList.some(res=>(res.buttonValue=='TIAOJIA'))" size="small" class="botton_five" :disabled="yiFenPeiRadio == ''" @click="riseInPriceQueryOneByidFun(yiFenPeiRadio)">调价</el-button>
          <el-button v-if="ButtonList.some(res=>(res.buttonValue=='KAIHUXINXI'))" size="small" class="botton_five" :disabled="yiFenPeiRadio == ''" @click="queryListsByPidFun(yiFenPeiRadio)">开户信息</el-button>
          <el-button v-if="ButtonList.some(res=>(res.buttonValue=='FENPEIZHANGHAO'))" size="small" class="botton_five" :disabled="yiFenPeiRadio == ''" @click="open(yiFenPeiRadio,'dialog1')">分配账号</el-button>
        </div>
        <div>
          <el-dropdown :hide-on-click="false" trigger="click" style="margin: 0 20px;">
            <el-link :underline="false">
              <span class="el-icon--left">
                <i class="iconfont iconicon_button_filtrate"></i>
              </span>
              筛选
            </el-link>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item v-for="(item, index) in table" :key="index">
                <el-checkbox v-model="item.status">{{ item.label }}</el-checkbox>
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
          <el-link v-if="ButtonList.findIndex(res=>(res.buttonValue=='DAOCHU'))!==-1" :underline="false" @click="load()">
            <span class="el-icon--left">
              <i class="iconfont iconicon_button_export1"></i>
            </span>
            导出
          </el-link>
        </div>
      </div>
      <div v-loading="tableLoading" class="card_info">
        <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width:100%" :data="tableData" tooltip-effect="dark" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55">
            <template slot-scope="scope">
              <el-radio v-model="yiFenPeiRadio" :label="scope.row">{{""}}</el-radio>
            </template>
          </el-table-column>
          <template v-for="(item, index2) in table">
            <el-table-column v-if="item.label == '操作'" :key="index2" fixed="right" :label="item.label" align="center" :width="item.width">
              <template slot-scope="scope">
                <el-dropdown :hide-on-click="false" trigger="click">
                  <el-button size="mini" class="bottom_one">更多</el-button>
                  <el-dropdown-menu slot="dropdown" style="text-align: left">
                    <el-dropdown-item v-if="ButtonList.some(res=>(res.buttonValue=='XIUGAI'))">
                      <el-button style="margin:5px 0" class="bottom_one" size="mini" @click="contractQueryDetailByIdFun(scope.row.id),addDialogTitle='修改',modifyType = false">
                        修改
                      </el-button>
                    </el-dropdown-item>
                    <el-dropdown-item>
                      <el-button size="mini" style="margin:5px 0" class="bottom_one" @click="$refs.ModifyTheRecord.contractQueryPageContractLogFun(scope.row.id)">更改记录</el-button>
                    </el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </template>
            </el-table-column>
            <el-table-column v-else :key="index2" :label="item.label" align="center" :width="item.width">
              <template slot-scope="scope">
                <div v-if="item.label == '站点名称'">
                  <span>{{scope.row.stations|stationsFun }}</span>
                </div>
                <el-link v-else-if="item.label == '合同ID'" class="table_link" :underline="false" @click="contractQueryDetailByIdFun(scope.row.id),addDialogTitle='查看'">{{scope.row.code}}</el-link>
                <div v-else-if=" item.label == '状态'">
                  <span v-if="scope.row.enable == 0 " style="color:#969799;">禁用</span>
                  <span v-else-if="scope.row.enable == 1 " style="color:#00A754;">启用</span>
                </div>
                <el-link v-else-if="item.label == '协作单位'&&ButtonList.findIndex(res=>(res.buttonValue=='XIEZUODANWEI'))!==-1" class="table_link" :underline="false" @click="cooperativeUnitFun(scope.row.supplierId)">协作单位</el-link>
                <div v-else-if="item.label == '是否包运输'">
                  <span v-if="scope.row.isCarriage == 1">是</span>
                  <span v-else>否</span>
                </div>
                <div v-else-if="item.label == '合同签订情况'">
                  <span v-if="scope.row.concludeAndSignStatus == 1">已签订</span>
                  <span v-else>未签订</span>
                </div>
                <div v-else-if="item.label == '华西云采注册情况'">
                  <span v-if="scope.row.loginStatus == 1">已注册</span>
                  <span v-else>未注册</span>
                </div>
                <div v-else-if="item.label == '合同有效期'">{{scope.row.startDay +' - '+scope.row.endDay}}</div>
                <!-- <span v-else-if="item.label == '合同有效期'" style="color:#969799;">{{ scope.row.contractBeginTime }} -- {{ scope.row.contractEndTime }}</span> -->
                <span v-else>{{ scope.row[item.prop] }}</span>
              </template>
            </el-table-column>
          </template>
        </el-table>
      </div>
      <div class="card_bottom">
        <div class="card_bottom_left">
          <div class="top_page_totle">总共{{ total }}条</div>
          <el-pagination :current-page.sync="tableParam.page" :page-size="tableParam.pageSize" :page-sizes="[10, 20, 30, 40,50,100,200,500,1000]" layout="prev,pager,sizes,next,jumper" :total="total" @size-change="sizeChange" @current-change="gettableData(),yiFenPeiRadio=''"></el-pagination>
        </div>
        <div>
          <el-button size="mini" icon="el-icon-refresh-right" class="bottom_all_two" @click="gettableData">刷新</el-button>
        </div>
      </div>
    </div>
    <!-- 添加·合同 -->
    <el-dialog v-dialogDrag :visible.sync="addDialog" width="1015px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">{{ addDialogTitle }}</span>
      <div class="dialoginfo FZYform scroll" style="height: calc(85vh - 230px);padding-right:5px;overflow: auto;">
        <el-form ref="reffromDate" :rules="rules" :inline="true" :model="formDate" label-width="110px">
          <div class="form-title">基本信息</div>
          <el-form-item>
            <span slot="label">合同类型</span>
            <div style="width: 340px;">{{formDate.contractType}}</div>
          </el-form-item>
          <el-form-item prop="firstPartyId">
            <span slot="label">权限公司</span>
            <el-select ref="selection1" v-model="formDate.firstPartyId" :placeholder="formDate.firstPartyIdPlaceholder" :disabled="modifyType" @change="companylistChangeFun(true,formDate.firstPartyId),$nextTick(()=>{formDate.firstParty = $refs.selection1.selectedLabel})">
              <el-option v-for="(item, index) in companylist" :key="index" :label="item.label" :value="item.value"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="contractSigningSubjectId">
            <span slot="label">合同签订主体</span>
            <el-select ref="selection1" v-model="formDate.contractSigningSubjectId" placeholder="请选择" :disabled="modifyType" @change="$nextTick(()=>{formDate.contractSigningSubject = $refs.selection1.selectedLabel})">
              <el-option v-for="(item, index) in roadWorkList" :key="index" :label="item.name" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item :key="formDate.firstPartyId" prop="stationsList">
            <span slot="label">站点名称</span>
            <el-select v-model="formDate.stationsList" :placeholder="formDate.stationsPlaceholder" multiple :disabled="modifyType" @change="stationsTypeFun()">
              <el-option v-for="(item, index)  in sitelist" :key="index" :label="item.label" :value="item.value"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="supplierId">
            <span slot="label">主合同单位</span>
            <el-select v-model="formDate.supplierId" filterable placeholder="请选择" style="width: 340px;" :disabled="modifyType" @change="changemainCompanyId(formDate.supplierId)">
              <el-option v-for="(item, index) in supplierList" :key="index" :label="item.name" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <span slot="label">供应商类别</span>
            <div style="width: 340px;">{{formDate.supplierType}}</div>
          </el-form-item>
          <el-form-item>
            <span slot="label">协作单位</span>
            <div style="width: 340px;">{{formDate.cooperativeUnionName}}</div>
          </el-form-item>
          <el-form-item prop="isCarriage">
            <span slot="label">是否包含运输</span>
            <el-select v-model="formDate.isCarriage" placeholder="请选择" :disabled="modifyType">
              <el-option label="是" :value="1"></el-option>
              <el-option label="否" :value="0"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="contractNumber">
            <span slot="label">合同编号</span>
            <el-input v-model="formDate.contractNumber" placeholder="请输入" clearable :disabled="modifyType" @blur="queryContractNumberFun()"></el-input>
          </el-form-item>
          <el-form-item prop="callForBidsNumber">
            <span slot="label">招标编号</span>
            <el-input v-model="formDate.callForBidsNumber" placeholder="请输入" clearable :disabled="modifyType"></el-input>
          </el-form-item>
          <el-form-item prop="concludeAndSignStatus">
            <span slot="label">合同签订情况</span>
            <el-select v-model="formDate.concludeAndSignStatus" placeholder="请选择" :disabled="modifyType">
              <el-option label="已签订" :value="1"></el-option>
              <el-option label="未签订" :value="0"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="loginStatus" label-width="140px">
            <span slot="label">华西云采注册情况</span>
            <el-select v-model="formDate.loginStatus" class="hyyc" placeholder="请选择" :disabled="modifyType">
              <el-option label="已注册" :value="1"></el-option>
              <el-option label="未注册" :value="0"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="linkman">
            <span slot="label">联系人</span>
            <el-input v-model="formDate.linkman" placeholder="请输入" clearable :disabled="modifyType"></el-input>
          </el-form-item>
          <el-form-item prop="phone">
            <span slot="label">联系电话</span>
            <el-input v-model="formDate.phone" placeholder="请输入" clearable :disabled="modifyType"></el-input>
          </el-form-item>
          <el-form-item prop="startDayendDay">
            <span slot="label">合同有效期</span>
            <el-date-picker v-model="formDate.startDayendDay" unlink-panels style="width:340px;" type="datetimerange" value-format="yyyy-MM-dd HH:mm:ss" start-placeholder="开始日期" end-placeholder="结束日期" :disabled="modifyType"></el-date-picker>
          </el-form-item>
          <el-form-item prop="isFirstSupply">
            <span slot="label">是否甲供合同</span>
            <el-select v-model="formDate.isFirstSupply" placeholder="请选择" :disabled="modifyType" @change="isFirstSupplyFun()">
              <el-option label="是" :value="1"></el-option>
              <el-option label="否" :value="0"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item v-show="formDate.isFirstSupply == 1" prop="code">
            <span slot="label">甲供工程</span>
            <el-select v-model="formDate.firstSupplyId" multiple placeholder="请选择" :disabled="modifyType">
              <el-option v-for="(v,k) in engineeringManagement" :key="k" :label="v.name" :value="v.id"></el-option>
            </el-select>
          </el-form-item>
          <div class="form-title">供应产品</div>
          <el-form-item prop="clearingSourceId">
            <span slot="label">结算单价来源</span>
            <el-select v-model="formDate.clearingSourceId" placeholder="请选择" :disabled="modifyType">
              <el-option v-for="(item, index) in theUnitPriceSource" :key="index" :label="item.itemName" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <div>
            <div style="padding-bottom: 10px;">
              <el-button size="mini" class="bottom_all" style="margin-left: 0;" :disabled="modifyType" @click="addItem()">
                <i class="icon iconfont iconicon_button_add" style="font-size: 12px;"></i>
                添加
              </el-button>
            </div>
            <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width:100%" :data="cplistArr" tooltip-effect="dark">
              <el-table-column label="原物料" align="center" width="150">
                <template slot-scope="scope">
                  <span v-if="scope.row.productName" class="table_link" style="cursor:pointer;" @click="ListChoiceTypeFun(scope.$index,scope.row.productId)">{{scope.row.productName}}</span>
                  <span v-else class="table_link" style="cursor:pointer;" @click="ListChoiceTypeFun(scope.$index)">选择</span>
                </template>
              </el-table-column>
              <el-table-column label="品牌" align="center" prop="brand" width="auto"></el-table-column>
              <el-table-column label="规格" align="center" prop="specification" width="auto"></el-table-column>
              <el-table-column label="产地" align="center" prop="originPlace" width="auto"></el-table-column>
              <el-table-column label="是否甲供" align="center">
                <template slot-scope="scope">
                  <el-select v-model="scope.row.isFirstSupply" placeholder="请选择" style="width: 100%;" :disabled="modifyType">
                    <el-option label="是" :value="1"></el-option>
                    <el-option label="否" :value="0"></el-option>
                  </el-select>
                </template>
              </el-table-column>
              <el-table-column label="保底含水率(%)" align="center">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.moistureContent" type="number" style="width: 100%;" :disabled="modifyType" @input="monitorValue(scope.row.moistureContent,scope.$index)"></el-input>
                </template>
              </el-table-column>
              <el-table-column label="结算方式" align="center" width="110">
                <template slot-scope="scope">
                  <el-select v-model="scope.row.settleMethod" placeholder="请选择" style="width: 100%;" :disabled="modifyType" @change="changeMethod(scope.$index)">
                    <el-option label="计量数" :value="1"></el-option>
                    <el-option label="货票数" :value="2"></el-option>
                  </el-select>
                </template>
              </el-table-column>
              <el-table-column label="货票比例‰" align="center">
                <template slot-scope="scope">
                  <el-input-number v-model="scope.row.invoiceProportion" style="width: 100%;" :disabled="modifyType || scope.row.settleMethod===1" :controls="false" :min="0" :max="1000"></el-input-number>
                </template>
              </el-table-column>
              <el-table-column label="过磅提示比例‰" align="center">
                <template slot-scope="scope">
                  <el-input-number v-model="scope.row.noticeProportion" style="width: 100%;" :disabled="modifyType || scope.row.settleMethod===1" :controls="false" :min="0" :max="1000"></el-input-number>
                </template>
              </el-table-column>
              <el-table-column label="条件接收方式" align="center" width="150">
                <template slot-scope="scope">
                  <el-select v-model="scope.row.receiveModeIdList" placeholder="请选择" style="width: 100%;" :disabled="modifyType" multiple @change="$forceUpdate()">
                    <el-option v-for="(v,k) in receiveModeIdArr" :key="k" :label="v.itemName" :value="v.id"></el-option>
                  </el-select>
                </template>
              </el-table-column>
              <el-table-column label="出厂价" align="center">
                <template slot-scope="scope">
                  <el-input-number v-model="scope.row.factoryPrice" :precision="2" style="width: 100%;" :disabled="modifyType" :controls="false"></el-input-number>
                </template>
              </el-table-column>
              <el-table-column v-if="headerNameType" label="站点运输价及到岸价" align="center" prop="specification" width="100">
                <template slot-scope="scope">
                  <el-link class="table_link" :underline="false" @click="getLandedPriceFun(scope.row)">查看</el-link>
                </template>
              </el-table-column>
              <el-table-column label="操作" align="left" prop="specification" width="100">
                <template slot-scope="scope">
                  <el-button size="mini" class="bottom_two" :disabled="modifyType" @click="deleteItem(scope.$index)">
                    <i class="icon iconfont iconicon_button_delete" style="font-size: 12px;"></i>
                    删除
                  </el-button>
                </template>
              </el-table-column>
            </el-table>
            <el-form-item style="margin-top:10px;">
              <span slot="label">集中供气费用</span>
              <el-input v-model="formDate.airFeedCost" placeholder="请输入" :disabled="modifyType" onkeypress='return( /\d|\./.test(String.fromCharCode(event.keyCode)))' @input="formDate.airFeedCost=$regExp.checkNum(formDate.airFeedCost)" @blur="formDate.airFeedCost=$regExp.blurCheckNum(formDate.airFeedCost)"><template slot="append">元/吨</template></el-input>
            </el-form-item>
          </div>
          <div class="form-title">结算规则</div>
          <el-row>
            <el-col :span="12">
              <el-form-item prop="clearingFormId">
                <span slot="label">结算方式</span>
                <el-select v-model="formDate.clearingFormId" placeholder="请选择" :disabled="modifyType">
                  <el-option v-for="(item, index) in clearingFromIdList" :key="index" :label="item.name" :value="item.id"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <div>
                <el-form-item prop="settlementInterval" class="zq">
                  <span slot="label">结算周期</span>
                  <el-select v-model="formDate.settlementInterval" placeholder="请选择" style="width: 100px;" :disabled="modifyType">
                    <el-option label="每月" :value="1"></el-option>
                    <el-option label="每3月" :value="2"></el-option>
                    <el-option label="每6月" :value="3"></el-option>
                    <el-option label="每12月" :value="4"></el-option>
                  </el-select>
                  <el-input-number v-model="formDate.stationDay" style="width: 50px!important;margin: 0 10px;" :max="31" :disabled="modifyType" :controls="false"></el-input-number>
                  <span>日 - 下一周期首月 N-1 日</span>
                </el-form-item>
              </div>
            </el-col>
          </el-row>
          <!-- <el-form-item prop="waterContent" label-width="130px">
            <span slot="label">保底含水率(%)</span>
            <el-input-number
              v-model="formDate.waterContent"
              :precision="2"
              style="width: 230px;"
              :max="100"
              :disabled="modifyType"
            ></el-input-number>
          </el-form-item>-->
          <!-- <div
            style="color:#FF0000;font-size: 12px;padding-bottom:18px;line-height: 20px;"
          >{{ text }}</div>-->
          <el-form-item prop="paymentMethod" :rules="[{required: true,message: '请选择付款方式',trigger: 'change',}]">
            <span slot="label">付款方式</span>
            <el-select v-model="formDate.paymentMethod" placeholder="请选择" :disabled="modifyType">
              <el-option label="账龄" :value="1"></el-option>
              <el-option label="比例" :value="2"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item v-show="formDate.paymentMethod==1" prop="aging" :rules="[{required: formDate.paymentMethod==1,message: '请选择账龄',trigger: 'change',}]">
            <span slot="label">账龄</span>
            <el-select v-model="formDate.aging" placeholder="请选择" :disabled="modifyType">
              <el-option label="1月" :value="1"></el-option>
              <el-option label="2月" :value="2"></el-option>
              <el-option label="3月" :value="3"></el-option>
              <el-option label="4月" :value="4"></el-option>
              <el-option label="5月" :value="5"></el-option>
              <el-option label="6月" :value="6"></el-option>
              <el-option label="7月" :value="7"></el-option>
              <el-option label="8月" :value="8"></el-option>
              <el-option label="9月" :value="9"></el-option>
              <el-option label="10月" :value="10"></el-option>
              <el-option label="11月" :value="11"></el-option>
              <el-option label="12月" :value="12"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item v-show="formDate.paymentMethod==2" prop="paymentRatio" :rules="[{required: formDate.paymentMethod==2,message: '请输入支付比例',trigger: 'change',}, {pattern:/^([1-9]+[\d]*(.[0-9]{1,2})?)$/, message: '小数不能超过2位'}]">
            <span slot="label">支付比例(%)</span>
            <el-input v-model="formDate.paymentRatio" type="number" style="width: 130px;" :disabled="modifyType" oninput="value=value>100?100:value" :controls="false"></el-input>
          </el-form-item>
          <el-form-item>
            <span slot="label">结算说明</span>
            <el-input v-model="formDate.explains" style="width: 800px;" type="textarea" placeholder="请输入" clearable :rows="2" resize="none" :disabled="modifyType" maxlength="200" show-word-limit></el-input>
          </el-form-item>
          <div class="form-title">增值服务</div>
          <el-form-item prop="processModel">
            <span slot="label">流程模式</span>
            <el-select v-model="formDate.processModel" placeholder="请选择" :disabled="modifyType" @change="processModelFun()">
              <el-option label="传统工艺流程模式" value="1"></el-option>
              <el-option label="电子工艺流程模式" value="0"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <span slot="label"></span>
            <el-button size="mini" class="bottom_all" style="margin-left: 0;" @click="stationsControlPointFun()">管控业务点</el-button>
          </el-form-item>
          <div class="form-title">附件</div>
          <FileComponent fileCode="contractFile" :disabled="modifyType" :files="files" @deleteFile="deleteFile" @uplodeSuccess="uplodeSuccess" />
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="addDialog = false">关 闭</el-button>
        <el-button v-show="!modifyType" class="bottom_all" style="margin-left: 24px;" :disabled="modifyType" @click="pagessubmitFromDate()">保 存</el-button>
      </span>
    </el-dialog>
    <!-- 业务管控点 -->
    <el-dialog v-dialogDrag :visible.sync="controlPoint_Dialog" width="800px">
      <span slot="title" class="dialog-title">管控业务点设置</span>
      <div class="dialoginfo">
        <div class="FZYguanKongYeWuDian">
          <table>管控业务点：</table>
          <div class="FZYcheckbox">
            <div v-if="formDate.processModel==1">
              <el-checkbox v-for="(v,k) in businessCheckbox" :key="k" :label="v.id" :disabled="true" checked>{{v.itemName}}</el-checkbox>
            </div>
            <el-checkbox-group v-else v-model="formDate.business">
              <el-checkbox v-for="(v,k) in businessCheckbox" :key="k" :label="v.id" :disabled="modifyType">{{v.itemName}}</el-checkbox>
            </el-checkbox-group>
          </div>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all" style="margin-left: 24px;" @click="controlPoint_Dialog = false">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 站点运输价及到岸价查看 -->
    <el-dialog v-dialogDrag :visible.sync="thePrice_Dialog" width="550px">
      <span slot="title" class="dialog-title">站点运输价及到岸价</span>
      <div class="dialoginfo">
        <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width:100%" :data="cplistArrList" tooltip-effect="dark">
          <el-table-column label="站点" align="center" prop="station" width="auto"></el-table-column>
          <el-table-column label="运输价" align="center" prop="yun" width="auto"></el-table-column>
          <el-table-column label="到岸价" align="center" prop="dao" width="auto"></el-table-column>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="thePrice_Dialog = false">关 闭</el-button>
      </span>
    </el-dialog>
    <!-- 协作单位 -->
    <el-dialog v-dialogDrag :visible.sync="cooperativeUnit_Dialog" width="550px">
      <span slot="title" class="dialog-title">协作单位</span>
      <div class="dialoginfo">
        <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width:100%" :data="cooperativeUnitArr" tooltip-effect="dark">
          <el-table-column label="协作单位" align="center" prop="name"></el-table-column>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="cooperativeUnit_Dialog = false">关 闭</el-button>
      </span>
    </el-dialog>
    <!-- 合同产品列表 -->
    <el-dialog v-dialogDrag :visible.sync="riseInPriceQueryOneByidType" width="550px">
      <span slot="title" class="dialog-title">合同产品列表</span>
      <div class="dialoginfo">
        <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width:100%" :data="riseInPriceQueryOneByidArr" tooltip-effect="dark">
          <el-table-column label="原物料" prop="productName" align="center"></el-table-column>
          <el-table-column label="品牌" prop="brand" align="center"></el-table-column>
          <el-table-column label="规格" prop="specification" align="center"></el-table-column>
          <el-table-column label="出厂价" align="center">
            <template slot-scope="scope">
              <el-link class="table_link" :underline="false" @click="QueryOneByidFun(scope.row.id)">价格设置</el-link>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="riseInPriceQueryOneByidType = false">关 闭</el-button>
      </span>
    </el-dialog>
    <!-- 价格设置-调价详情 -->
    <el-dialog v-dialogDrag :visible.sync="QueryOneByidType" width="800px">
      <span slot="title" class="dialog-title">价格设置</span>
      <div class="dialoginfo">
        <el-form ref="contractRawMoneySaveForm" label-width="80px" :model="contractRawMoneySaveForm" :rules="contractRawMoneySaveFormRules" class="FZYform2">
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="价格" prop="money">
                <el-input v-model="contractRawMoneySaveForm.money" type="Number" placeholder :controls="false">
                  <template slot="append">元/吨</template>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="生效日期" prop="startTime">
                <el-date-picker v-model="contractRawMoneySaveForm.startTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择日期时间"></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <div style="margin-left: 24px;"><FileComponent fileCode="contractFile" :files="files2" @deleteFile="deleteFile2" @uplodeSuccess="uplodeSuccess2" /></div>
            </el-col>
            <el-col :span="24" style="margin-bottom: 20px;">
              <el-button class="bottom_all" @click="contractRawMoneySaveFun()">添加</el-button>
            </el-col>
          </el-row>
        </el-form>
        <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width:100%" :data="QueryOneByidArr" tooltip-effect="dark">
          <el-table-column label="价格" prop="money" align="center">
            <template slot-scope="scope">
              {{scope.row.money}} 元/吨
            </template>
          </el-table-column>
          <el-table-column label="生效日期" prop="startTime" align="center"></el-table-column>
          <el-table-column label="附件" prop="startTime" align="center"  width="120">
            <template slot-scope="scope">
              <el-button size="mini" class="bottom_all_two" @click="lookFile(scope)">查看</el-button>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" width="120">
            <template slot-scope="scope">
              <el-link class="table_link" :underline="false" @click="contractRawMoneyDeletesFun(scope.row.id)">删除</el-link>
            </template>
          </el-table-column>
        </el-table>
        <div class="card_bottom">
          <div class="card_bottom_left">
            <div class="top_page_totle">总共{{ QueryOneByidObject.total }}条</div>
            <el-pagination :current-page.sync="QueryOneByidObject.page" :page-size="QueryOneByidObject.pageSize" layout="prev, pager, next, jumper" :total="QueryOneByidObject.total" @current-change="QueryOneByidFun()"></el-pagination>
          </div>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="QueryOneByidType = false">关 闭</el-button>
      </span>
    </el-dialog>
    <!-- 开户信息 -->
    <el-dialog v-dialogDrag :visible.sync="AllqueryListsByPid" width="550px">
      <span slot="title" class="dialog-title">开户信息维护</span>
      <div class="dialoginfo">
        <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width:100%" :data="queryListsByPidArr" tooltip-effect="dark">
          <el-table-column label="单位名称" prop="name" align="center"></el-table-column>
          <el-table-column label="开户信息">
            <template slot-scope="scope">
              <el-link class="table_link" :underline="false" @click="contractAccountGetDetailFun(scope.row.id,scope.$index+1)">开户信息</el-link>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="AllqueryListsByPid = false">关 闭</el-button>
      </span>
    </el-dialog>
    <!-- 开户信息详情-编辑 -->
    <el-dialog v-dialogDrag :visible.sync="contractAccountGetDetailType" width="800px">
      <span slot="title" class="dialog-title">开户信息</span>
      <div class="dialoginfo">
        <el-form ref="contractAccountSaveForm" label-width="130px" :model="contractAccountSaveForm" :rules="contractAccountSaveRules" class="FZYform2">
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="法定代表人" prop="name" :rules="[{required: true,message: '请输入法定人',trigger: 'blur',}]">
                <el-input v-model="contractAccountSaveForm.name"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="法人身份证号码" prop="identityCard">
                <el-input v-model="contractAccountSaveForm.identityCard"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="合同条款" prop="contractPact" :rules="[{required: true,message: '请输入合同条款',trigger: 'blur',}]">
                <el-input v-model="contractAccountSaveForm.contractPact"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="统一社会信用代码" prop="unifiedSocialCreditCode" :rules="[{required: true,message: '请输入信用代码',trigger: 'blur',}]">
                <el-input v-model="contractAccountSaveForm.unifiedSocialCreditCode"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="收款方式">
                <div style="width: 100px;">现金</div>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="单位开户银行">
                <el-input v-model="contractAccountSaveForm.bankDepositA"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="单位开户账号">
                <el-input v-model="contractAccountSaveForm.accountA"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="开户银行联行号">
                <el-input v-model="contractAccountSaveForm.bankNumberA"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="收款方式">
                <div style="width: 100px;">电子承兑</div>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="单位开户银行">
                <el-input v-model="contractAccountSaveForm.bankDepositB"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="单位开户账号">
                <el-input v-model="contractAccountSaveForm.accountB"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="开户银行联行号">
                <el-input v-model="contractAccountSaveForm.bankNumberB"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="收款方式">
                <div style="width: 100px;">商票</div>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="单位开户银行">
                <el-input v-model="contractAccountSaveForm.bankDepositC"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="单位开户账号">
                <el-input v-model="contractAccountSaveForm.accountC"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="开户银行联行号">
                <el-input v-model="contractAccountSaveForm.bankNumberC"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="收款方式">
                <div style="width: 100px;">其他</div>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="单位开户银行">
                <el-input v-model="contractAccountSaveForm.bankDepositD"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="单位开户账号">
                <el-input v-model="contractAccountSaveForm.accountD"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="开户银行联行号">
                <el-input v-model="contractAccountSaveForm.bankNumberD"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="contractAccountGetDetailType = false">关 闭</el-button>
        <el-button class="bottom_all" style="margin-left: 24px;" @click="contractAccountSaveFun()">保 存</el-button>
      </span>
    </el-dialog>
    <!-- 列表单选 -->
    <el-dialog v-dialogDrag :visible.sync="ListChoiceType" width="980px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">选择</span>
      <div class="dialogOtherinfo">
        <div style="position: relative;margin-bottom:10px;height:30px;">
          <div class="form-title">原物料查询</div>
          <div style="position: absolute;right: 0;top: 0;">
            原物料名称：
            <el-input v-model="checkName" size="mini" style="width: 130px;"></el-input>
            原物料类型：
            <el-select v-model="checkTypeId" placeholder="请选择">
              <el-option label="全部" value=""></el-option>
              <el-option v-for="(v,k) in checkTypeIdList" :key="k" :label="v.itemName" :value="v.id"></el-option>
            </el-select>
            <el-button size="mini" class="bottom_all but1" style="margin-left: 10px;" @click="ListChoicePagingFun()">搜索</el-button>
          </div>
        </div>
        <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width:100%" :data="ListChoiceData" tooltip-effect="dark" highlight-current-row @row-click="ListChoiceFun">
          <el-table-column width="55">
            <template slot-scope="scope">
              <el-radio v-model="ListChoiceRadio" :label="scope.row.id">{{""}}</el-radio>
            </template>
          </el-table-column>
          <el-table-column prop="barCode" label="原物料编号" width="auto" align="center"></el-table-column>
          <el-table-column prop="name" label="原物料名称" width="auto" align="center"></el-table-column>
          <el-table-column prop="brand" label="品牌" width="auto" align="center"></el-table-column>
          <el-table-column prop="specification" label="规格" width="auto" align="center"></el-table-column>
          <el-table-column prop="originPlace" label="产地" width="auto" align="center"></el-table-column>
          <el-table-column prop="typeName" label="类型" width="auto" align="center"></el-table-column>
          <el-table-column prop="enable" label="状态" width="auto" align="center">
            <template slot-scope="scope">
              <span v-if="scope.row.enable == 0" style="color:#969799;">禁用</span>
              <span v-if="scope.row.enable == 1" style="color:#00A754;">启用</span>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination :current-page.sync="ListChoicePaging.page" :page-size="ListChoicePaging.pageSize" layout="total, prev, pager, next, jumper" :total="ListChoicePaging.total" @current-change="ListChoicePagingFun(true)"></el-pagination>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="ListChoiceType = false">取 消</el-button>
        <el-button :disabled="modifyType" class="bottom_all" style="margin-left: 24px;" @click="ListChoiceAddFun()">确 定</el-button>
      </span>
    </el-dialog>
    <ModifyTheRecord ref="ModifyTheRecord"></ModifyTheRecord>
    <diaLog1 :dialog="dialog1" :low="low" :supplierId="supplierId" @reset="reset1" @submit="submit"></diaLog1>
    <!-- 查看附件 -->
    <LookFile :visible.sync="lookFileVisible" :config="lookFileConfig" />
  </div>
</template>

<script>
import mixin from "@/mixins/ICPSmixin.js";
import FileComponent from '@/views/platform/ICPS/internetSales/components/fileComponent';
import LookFile from '@/components/File/LookFile';
import {
  queryPage,
  batchUpdateOrDelete,
  updateSortNum,
  saveOrUpdate,
  Download,
  engineeringManagementQueryPage,
  processes_collection,
  contractSaveOrUpdate,
  contractQueryDetailById,
  riseInPriceQueryOneByid,
  QueryOneByid,
  contractRawMoneySave,
  contractRawMoneyDeletes,
  contractAccountGetDetail,
  contractAccountSave,
  getLandedPrice,
  queryContractNumber,
  cooperationqueryListsByPid,
  queryPageBycontractids
} from "@/api/GHnumber/contract.js";
import { querysupplierPage, queryListsByPid } from "@/api/GHnumber/supplier.js";
import { getOrganizationBytypes } from '@/api/internetSales/chanceManagement'
import {
  getDicType, getDicsType,
  // orgUserTree 
} from "@/api/common.js";
import { queryPage as getUser } from "@/api/basedata/user.js";
import { getUserInfo } from "@/utils/auth.js";
import { getUserAutList } from "@/api/common.js";
import ModifyTheRecord from './modifyTheRecord';
const diaLog1 = () => import("../dialog/contract1")
export default {
  components: { FileComponent, LookFile, ModifyTheRecord, diaLog1 },
  mixins: [mixin],
  watch: {
    "formDate.startDayendDay"() {
      this.formDate.startDay = this.formDate.startDayendDay[0];
      this.formDate.endDay = this.formDate.startDayendDay[1];
    },
    yiFenPeiRadio: {
      handler: function (val) {
        this.ids = [val.id]
      },
      deep: false,
    },
  },
  data() {
    var userCard = (rule, value, callback) => {
      //验证身份证号码
      var reg = new RegExp(
        /^(([1][1-5])|([2][1-3])|([3][1-7])|([4][1-6])|([5][0-4])|([6][1-5])|([7][1])|([8][1-2]))\d{4}(([1][9]\d{2})|([2]\d{3}))(([0][1-9])|([1][0-2]))(([0][1-9])|([1-2][0-9])|([3][0-1]))\d{3}[0-9xX]$/
      );
      if (!reg.test(value)) {
        callback(new Error("请输入正确的身份证号码"));
      } else {
        callback();
      }
    };
    return {
      roadWorkList: [], // 合同签订主体数据
      checkName: '',
      checkTypeId: '',
      checkTypeIdList: [],
      UserInfo: "",
      startDayendDay: [],
      cplistArrList: [],
      /*表格增删改查及下载接口*/
      queryPage: queryPage,
      batchUpdateOrDelete: batchUpdateOrDelete, //启用禁用接口
      updateSortNum: updateSortNum,
      saveOrUpdate: saveOrUpdate,
      DownloadURL: Download,
      /*表格数据*/
      table: [
        { label: "合同ID", width: "120", prop: "code", status: true },
        { label: "合同类型", width: "120", prop: "contractType", status: true },
        {
          label: "甲方公司",
          width: "auto",
          prop: "firstParty",
          status: true,
        },
        { label: "站点名称", width: "120", prop: "stations", status: true },
        {
          label: "主合同单位",
          width: "auto",
          prop: "supplierName",
          status: true,
        },
        {
          label: "供应商类别",
          width: "120",
          prop: "supplierType",
          status: true,
        },
        {
          label: "协作单位",
          width: "100",
          prop: "cooperativeCompany",
          status: true,
        },
        { label: "是否包运输", width: "120", prop: "isCarriage", status: true },
        { label: "车辆租赁合同编号", width: "auto", prop: "carContractNumber", status: true },
        {
          label: "原物料合同编号",
          width: "120",
          prop: "contractNumber",
          status: true,
        },
        {
          label: "合同签订情况",
          width: "auto",
          prop: "concludeAndSignStatus",
          status: true,
        },
        {
          label: "华西云采注册情况",
          width: "120",
          prop: "loginStatus",
          status: true,
        },
        { label: "合同有效期", width: "145", prop: "startDay", status: true },
        {
          label: "招标编号",
          width: "120",
          prop: "callForBidsNumber",
          status: true,
        },
        {
          label: "合作等级",
          width: "auto",
          prop: "cooperationClass",
          status: true,
        },
        { label: "状态", width: "120", prop: "", status: true },
        { label: "操作", width: "100", prop: "", status: true, fixed: "right" },
      ],
      modifyType: false, //修改是否可以状态
      text:
        "含水率规则：0≤x≤5%，按照5%结算；5%＜X≤8%，按照8%结算；8%<x≤13%，按照实测结算；13%<x，按照实测结算，并5元/吨处罚",
      orgUsers: [], //用户账号
      clearingFromIdList: [
        // { id: '0', name: '双控' },
        // { id: '1', name: '图算' },
        { id: '2', name: '实结' },], //结算方式
      companylist: [], //甲方公司
      sitelist: [], //站点名称
      supplierList: [], //主合同单位名称
      AForContract: [], //是否甲供合同
      theUnitPriceSource: [
        {
          id: "1",
          itemName: "以信息价结算",
        },
        {
          id: "2",
          itemName: "以内部价结算",
        },
        {
          id: "3",
          itemName: "以市场价结算",
        },
        {
          id: "4",
          itemName: "以出厂价结算",
        },
        {
          id: "5",
          itemName: "以到岸价结算",
        },
      ], //单价来源
      engineeringManagement: [], //甲供工程
      thePrice_Dialog: false, //价格表弹窗
      controlPoint_Dialog: false, //业务管控点弹窗
      cooperativeUnit_Dialog: false, //协作单位弹窗
      rules: {
        firstPartyId: [
          { required: true, message: "请选择甲方公司", trigger: "change" },
        ],
        contractSigningSubjectId: [
          { required: true, message: "请选择合同签订主体", trigger: "change" },
        ],
        stationsList: [
          { required: true, message: "请选择站点名称", trigger: "change" },
        ],
        supplierId: [
          { required: true, message: "请选择主合同单位", trigger: "change" },
        ],
        isCarriage: [
          { required: true, message: "请选择是否包含运输", trigger: "change" },
        ],
        contractNumber: [
          { required: true, message: "请输入合同编号", trigger: "change" },
        ],
        callForBidsNumber: [
          { required: true, message: "请输入招标编号", trigger: "change" },
        ],
        concludeAndSignStatus: [
          { required: true, message: "请选择合同签订情况", trigger: "change" },
        ],
        loginStatus: [
          {
            required: true,
            message: "请选择华西云采注册情况",
            trigger: "change",
          },
        ],
        linkman: [{ required: true, message: "请输入联系人", trigger: "change" }],
        phone: [
          { required: true, message: "请输入联系电话", trigger: "change" },
          { min: 11, max: 11, message: "手机号格式错误", trigger: "change" },
        ],
        startDayendDay: [
          { required: true, message: "请选择合同有效期", trigger: "change" },
        ],
        isFirstSupply: [
          { required: true, message: "请选择是否甲供合同", trigger: "change" },
        ],
        clearingSourceId: [
          { required: true, message: "请选择结算单价来源", trigger: "change" },
        ],
        clearingFormId: [
          { required: true, message: "请选择结算方式", trigger: "change" },
        ],
        waterContent: [
          { required: true, message: "请选择保底含水率", trigger: "change" },
        ],
        settlementInterval: [
          { required: true, message: "请输入结算周期", trigger: "change" },
        ],
        processModel: [
          { required: true, message: "请选择流程模式", trigger: "change" },
        ],
      },
      formDate: {
        userType: [],
        stationsList: [],
        stations: '',
        startDayendDay: [],
        id: "",
        contractTypeId: "1",
        contractType: "原物料",
        firstParty: "", //甲方
        supplierName: "", //供应商
        supplierTypeId: "", //供应商类型id
        userId: "",
        userName: "",
        firstSupplyName: "", //甲供合同
        clearingSource: "", //结算原
        clearingForm: "", //结算方式
        accessory: [], //附件
        cooperationClass: "合作等级", //甲方公司里面出来的
        cooperationClassId: "合作等级id", //甲方公司里面出来的
        business: [], //业务点1，2，3
        cplist: [], //添加：原物料列表
        firstSupplyId: "",
        settlementInterval: "", //结算周期，每多少月
      },
      cplistArr: [], //供应产品列表显示部分
      businessCheckbox: [], //业务点
      userArry: [], //用户列表
      cooperativeUnitArr: [], //外协单位列表
      riseInPriceQueryOneByidType: false,
      riseInPriceQueryOneByidArr: [], //调价列表
      contractId: "", //原物料列表
      QueryOneByidType: false,
      QueryOneByidArr: [], //调价列表
      receiveModeIdArr: [], //接收方式
      QueryOneByidObject: {
        //调价分页
        page: 1,
        pageSize: 10,
        total: 0,
      },
      contractRawMoneySaveForm: { startTime: "" },
      contractRawMoneySaveFormRules: {
        money: [{ required: true, message: "请输入价格", trigger: "blur" }],
        startTime: [
          { required: true, message: "请选择生效日期", trigger: "blur" },
        ],
      },
      AllqueryListsByPid: false,
      queryListsByPidArr: [], //开户信息-协作单位合并列表
      contractAccountGetDetailType: false,
      //开户信息表单
      contractAccountSaveForm: {
        contractPactId: "", //合同条约id
        contractPact: "", //合同条约
      },
      contractAccountSaveRules: {
        identityCard: [
          { required: true, validator: userCard, trigger: "change" },
        ], //身份证
      },
      headerNameType: false,
      ListChoiceType: false,//单选表格是否打开
      ListChoiceData: [],//单选表格数据
      ListChoiceRadio: '',//单选表格选中项
      ListChoiceRadioCopy: '',//当前打开的单选表格选中项
      ListChoiceRadioRow: {},//单选表格选中的对象
      ListChoiceDataIndex: '',//点击的表格数据下标
      ListChoicePaging: {//单选表格分页
        pageSize: 5,
        page: 1,
        total: 0
      },
      files: [],
      files2: [],
      low: '',
      supplierId: '',
      dialog1: false,
      yiFenPeiRadio: '',

      lookFileVisible: false,
      lookFileConfig: {},
    };
  },
  async created() {
    this.UserInfo = await getUserInfo();
    this.companylist = await getUserAutList()
    const arr = this.companylist.map(item=>item.children)
    arr.forEach(item=>{
      item.forEach(sItem=>{
        this.sitelist.push(sItem)
      })
    })
    let params = {
      page: 1,
      pageSize: 10000,
    };
    engineeringManagementQueryPage({
      isAssess: 5,
      page: 1,
      pageSize: 10000,
      status: 1,
      armorForMaterials: 1
    }).then((res) => {
      this.engineeringManagement = res.data.data;
    });
    querysupplierPage(params).then((res) => {
      this.supplierList = res.data.data;
    });
    getDicType({ code: "MATtype" }).then((res) => {
      this.checkTypeIdList = res.data.items; //
    });
    getDicType({ code: "receiveType" }).then((res) => {
      this.receiveModeIdArr = res.data.items; //
    });
    getUser({
      page: 1,
      pageSize: 90000,
      userEentrance: "entrance_manager",
    }).then((res) => {
      this.userArry = res.data.data; //所有账号
    });
    getOrganizationBytypes({typeId:'19da56b9e85648059e3cf1e7da497da4,110572600018735104'}).then(res => {
      if (res.code === 1001) {
        this.roadWorkList = res.data;
      }
    })
  },
  methods: {
    lookFile({row}) { // 查看附件
      this.lookFileVisible = true;
      this.lookFileConfig = row;
    },
    monitorValue(value, index) {
      if (value * 1 < 0 || value * 1 > 100) {
        this.cplistArr[index].moistureContent = '';
        this.$message.warning('含水率不能超过0~100范围限制');
        return
      }
      this.cplistArr[index].moistureContent = value.replace(/^(-)*(\d+)\.(\d\d).*$/, "$1$2.$3");
    },
    changeMethod (index) {
      const copyData = JSON.parse(JSON.stringify(this.cplistArr));
      const newData = copyData.map((item, idx) =>(index===idx?{...item, invoiceProportion: 0, noticeProportion: 0}:{...item}));
      this.cplistArr = newData;
    },
    /**分配账号*/
    open(low, key) {
      this.supplierId = low.supplierId
      this.low = low.id;
      this[key] = true;
    },
    reset1(key) {
      this[key] = false;
    },
    submit(key) {
      this[key] = false;
    },
    /**
     * @Description: 删除附件
     * @Param: 
     * @Author: wangwangwang
     */
    deleteFile(index) {
      console.log(this.files);
      this.files.splice(index, 1);
    },
    deleteFile2(index) {
      console.log(this.files2);
      this.files2.splice(index, 1);
    },
    /**
     * @Description: 上传成功
     * @Param: 
     * @Author: wangwangwang
     */
    uplodeSuccess(data) {
      const params = {
        name: data.fileName,
        fileName: data.fileName,
        fileUrl: data.fileUrl,
        path: data.fileUrl,
        fileType: 1,
        type: 1,
        createTime: new Date().Format('yyyy-MM-dd hh:mm:ss'),
      }
      this.files.push(params);
    },
    uplodeSuccess2(data) {
      const params = {
        name: data.fileName,
        fileName: data.fileName,
        fileUrl: data.fileUrl,
        path: data.fileUrl,
        fileType: 1,
        type: 1,
        createTime: new Date().Format('yyyy-MM-dd hh:mm:ss'),
      }
      this.files2.push(params);
    },
    isFirstSupplyFun() {
      if (this.formDate.isFirstSupply == 0) {
        this.formDate.firstSupplyId = "";
      }
    },
    //获取已选择站点名称的业务点
    stationsControlPointFun(type) {
      if (this.formDate.stationsList.length == 0) {
        this.$message({
          message: '请先选择站点！',
          type: 'warning'
        });
        return
      }
      if (this.formDate.processModel == undefined) {
        this.$message({
          message: '请先选择流程模式！',
          type: 'warning'
        });
        return
      }
      getDicsType({ codes: "collaboration,nomarket,personaluse,market" }).then(
        (res) => {
          this.businessCheckbox = [];
          res.data.market.items.forEach((v) => {
            this.businessCheckbox.push(v);
          });
          if (!type) {
            this.controlPoint_Dialog = true;
            if (!this.formDate.id && this.formDate.processModel == 0) {
              processes_collection(this.formDate.stationsList).then((res2) => {
                if (res2.data ?.length > 0) {
                  this.formDate.business = res2.data.filter((dataRes) => this.businessCheckbox.some((box) => box.id == dataRes))
                }
              })
            }
          }
        });
    },
    //选择甲方公司后显示对应站点名称
    companylistChangeFun(type, companyId) {
      if (type) {
        this.cplistArr = []
        this.formDate.stationsList = [];
        this.cplistArr.forEach((e) => {
          e.productId = ''
          e.productName = ''
          e.specification = ''
          e.originPlace = ''
          e.specificationId = ''
          e.brand = ''
          e.brandId = ''
          e.rawId = ''
        })
      }
      this.sitelist = this.companylist.find((res) => res.value == companyId).children
    },
    //调用父级init
    init() {
      this.$emit("sumbit");
    },
    initt(data) {
      /*重置数据*/
      this.tableParam = data;
      this.gettableData();
    },
    srarch(data) {
      this.tableParam = data;
      this.gettableData();
    },
    //主合同单位选择后，带出对应参数[供应商类别,协作单位]
    async changemainCompanyId(e, type) {
      if (!type) {
        this.formDate.cooperativeUnionName = ''
        this.formDate.cooperativeUnion = ''
      }
      let item = this.supplierList.find((res) => res.id == e);
      this.formDate.supplierType = item.typeName;
      this.formDate.supplierTypeId = item.typeId;
      // console.log(JSON.parse(JSON.stringify(item.externalCompanyId)))
      //获取当前主供应商账号的外部公司id的组织树
      // this.orgUsers = await orgUserTree(item.externalCompanyId);
      /**协作单位 */
      cooperationqueryListsByPid({ supplierId: e }).then((res) => {
        if (res.data) {
          let text = "";
          text = res.data.map((item) => {
            return item.name;
          }).join(",");
          this.formDate.cooperativeUnionName = text;
          this.$forceUpdate()
          this.formDate.cooperativeUnion = res.data.map((item) => {
            return {
              id: item.id,
              name: item.name
            }
          })
          this.formDate.cooperativeUnion = JSON.stringify(this.formDate.cooperativeUnion)
        }
      })
    },
    /*表单*/
    addItem() {
      let data = {
        id: "",
        rawId: "", //原物料id
        productId: "", //产品id
        productName: "", //产品名称
        contractId: "",
        brand: "", //品牌
        brandId: "", //品牌id
        specification: "", //规格
        originPlace: '',
        specificationId: "", //规格id
        moistureContent: "", //含水
        settleMethod: '',
        invoiceProportion: '',
        noticeProportion: '',
        receiveMode: "", //接收方式
        receiveModeId: "", //接收方式id
        receiveModeIdList: [],//接收方式
        factoryPrice: "0",
        shippingCharge: "200",
        cif: "300",
        type: "1",
      };
      this.cplistArr.push(data);
    },
    deleteItem(index) {
      this.cplistArr.splice(index, 1);
    },
    /*添加保存*/
    pagessubmitFromDate() {
      this.$refs.reffromDate.validate((valid) => {
        if (valid) {
          let type = false
          this.cplistArr.forEach((v) => {
            if (!v.productId || v.isFirstSupply == undefined || !v.receiveModeIdList || !v.factoryPrice) {
              type = true
            }
          })
          for (let i = 0; i < this.cplistArr.length; i+=1) {
            if ((!(this.cplistArr[i].invoiceProportion < this.cplistArr[i].noticeProportion)) && this.cplistArr[i].settleMethod===2) {
              this.$message({
                message: '过磅提示比例必须大于货票比例',
                type: 'warning'
              });
              return
            }
          }
          if (type) {
            this.$message({
              message: '请检查表格数据是否完整！',
              type: 'warning'
            });
            return
          }
          //站点数据重装-开始
          if (this.formDate.stationsList.length > 0) {
            let arr = [];
            this.formDate.stationsList.forEach((v) => {
              this.sitelist.forEach((v2) => {
                if (v == v2.value) {
                  arr.push({
                    id: v,
                    name: v2.label,
                  });
                }
              });
            });
            this.formDate.stations = arr;
          }
          //站点数据重装-结束
          this.formDate.supplierName = this.$fromatTable(
            this.supplierList,
            this.formDate.supplierId,
            "id",
            "name"
          );
          this.formDate.supplierTypeId = this.$fromatTable(
            this.supplierList,
            this.formDate.supplierId,
            "id",
            "typeId"
          );
          this.formDate.clearingSource = this.$fromatTable(
            this.theUnitPriceSource,
            this.formDate.clearingSourceId,
            "id",
            "itemName"
          );
          this.formDate.clearingForm = this.$fromatTable(
            this.clearingFromIdList,
            this.formDate.clearingFormId,
            "id",
            "name"
          );
          this.formDate.cooperationClass = this.$fromatTable(
            this.supplierList,
            this.formDate.supplierId,
            "id",
            "gradeName"
          );
          this.formDate.cooperationClassId = this.$fromatTable(
            this.supplierList,
            this.formDate.supplierId,
            "id",
            "gradeId"
          );
          //供应产品数据重组-开始
          let alldata = this.cplistArr.filter((res) =>
            this.formDate.cplist.some((item) => res.id == item.id)
          );
          alldata.forEach((res) => {
            res.type = 2; //2是修改
          });
          let deleteData = this.formDate.cplist.filter(
            (res) => !alldata.some((item) => res.id == item.id)
          );
          deleteData.forEach((res) => {
            res.type = 0; //0是删除
          });
          let addData = this.cplistArr.filter(
            //新增的默认写死为 1；1
            (res) => !alldata.some((item) => res.id == item.id)
          );
          this.formDate.cplist = [...alldata, ...deleteData, ...addData];
          //供应产品数据重组-结束
          //业务点数据重组-开始
          if(typeof this.formDate.business === 'string') {
              let arr = [];
              JSON.parse(this.formDate.business).forEach((v) => {
                this.businessCheckbox.forEach((v2) => {
                    if (v == v2.id) {
                    arr.push({
                        id: v,
                        name: v2.itemName,
                        type: 1
                    });
                    }
                });
              });
              this.formDate.business = arr;
          } else {
              let arr = [];
              this.formDate.business.forEach((v) => {
                this.businessCheckbox.forEach((v2) => {
                    if (v == v2.id) {
                    arr.push({
                        id: v,
                        name: v2.itemName,
                        type: 1
                    });
                    }
                });
              });
              this.formDate.business = arr;
          }
          
          //业务点数据重组-结束
          this.formDate.accessory = JSON.stringify(this.files);
          this.formDate.business = JSON.stringify(this.formDate.business);
          this.formDate.stations = JSON.stringify(this.formDate.stations);
          this.formDate.cplist.forEach((v) => {
            if (v.type != 0 && v.receiveModeIdList.length > 0) {
              let list = []
              v.receiveModeIdList.forEach((v2) => {
                let itemName = this.receiveModeIdArr.find((res) => res.id == v2).itemName
                list.push({ id: v2, name: itemName })
              })
              v.receiveModeId = JSON.stringify(list)
              console.log(JSON.parse(JSON.stringify(v.receiveModeId)));
            } else {
              v.receiveModeId = ''
            }
          })
          const arr = [];
          if(this.formDate.firstSupplyId && Array.isArray(this.formDate.firstSupplyId)) {
              for (let i = 0; i < this.formDate.firstSupplyId.length; i++) {
            for (let j = 0; j < this.engineeringManagement.length; j++) {
              if(this.formDate.firstSupplyId[i] == this.engineeringManagement[j].id) {
                arr.push({
                  engineeringId: this.engineeringManagement[j].id,
                  engineeringName: this.engineeringManagement[j].name
                })
              }
            }
          }
          }
          
          
          contractSaveOrUpdate({...this.formDate, firstSupplyId: JSON.stringify(arr)}).then((res) => {
            if (res.code == 1001) {
              this.addDialog = false;
              this.$message.success('操作成功');
              this.init();
            }
          });
        } else {
          return false;
        }
      });
    },
    //获取合同详情
    contractQueryDetailByIdFun(d) {
      this.headerNameType = true
      this.addDialog = true;
      this.modifyType = true;
      this.$nextTick(() => {
        this.$refs.reffromDate.resetFields();
      })
      this.cplistArr = [];
      contractQueryDetailById({ id: d }).then(async (res) => {
        this.formDate = { ...this.formDate, ...res.data.contract };
        this.changemainCompanyId(this.formDate.supplierId, true)
        this.formDate.startDayendDay = [];
        this.formDate.startDayendDay[0] = this.formDate.startDay;
        this.formDate.startDayendDay[1] = this.formDate.endDay;
        this.formDate.cplist = this.copy(res.data.list);
        this.cplistArr = this.copy(res.data.list);
        this.cplistArr.forEach((v) => {
          v.receiveModeId = JSON.parse(v.receiveModeId)
          if (v.receiveModeId && v.receiveModeId.length > 0) {
            let arr = []
            v.receiveModeId.forEach((v) => {
              arr.push(v.id)
            })
            v.receiveModeIdList = arr
          } else {
            v.receiveModeIdList = []
          }
        })
        await this.companylistChangeFun(false, this.formDate.firstPartyId); //选择甲方公司后显示对应站点名称
        if (this.formDate.business) {
          let arr2 = [];
          JSON.parse(this.formDate.business).forEach((v) => {
            arr2.push(v.id);
          });
          this.formDate.business = arr2;
        }
        console.log(this.formDate.userType)
        this.files = JSON.parse(this.formDate.accessory) || [];
        //判断公司-站点权限是否包含返回的详情id值，在就回显，不在就回显提示信息placeholder
        let type1 = this.companylist.findIndex((res) => res.value == this.formDate.firstPartyId)
        if (type1 == -1) {
          this.formDate.firstPartyId = ''
          this.formDate.firstPartyIdPlaceholder = this.formDate.firstParty
          let text = '';
          JSON.parse(this.formDate.stations).forEach((v) => {
            text = text + v.name + ' ';
          });
          this.formDate.stations = '';
          this.formDate.stationsList = [];
          this.formDate.stationsPlaceholder = text;
        } else {
          if (this.formDate.stations) {
            let arr1 = [];
            JSON.parse(this.formDate.stations).forEach((v) => {
              arr1.push(v.id);
            });
            this.formDate.stationsList = arr1;
          } else {
            this.formDate.stationsList = [];
          }
        }
        await this.stationsControlPointFun(true); //获取已选择站点名称的业务点
        // reffromDate
        this.$forceUpdate();
        console.log(JSON.parse(JSON.stringify(this.formDate)));
      });
    },
    //调价列表
    riseInPriceQueryOneByidFun(d) {
      this.contractId = d.id;
      this.riseInPriceQueryOneByidType = true;
      riseInPriceQueryOneByid({ contractId: this.contractId }).then((res) => {
        this.riseInPriceQueryOneByidArr = res.data;
      });
    },
    //价格设置-调价详情-列表
    QueryOneByidFun(d) {
      this.QueryOneByidType = true;
      this.QueryOneByidArr = [];
      this.contractRawMoneySaveForm.startTime = "";
      this.QueryOneByidObject.contractId = this.contractId;
      if (d) {
        this.QueryOneByidObject.rawId = d;
      }
      QueryOneByid(this.QueryOneByidObject).then((res) => {
        this.QueryOneByidArr = res.data.data;
        this.QueryOneByidObject.total = res.data.totalRows;
      });
    },
    //价格设置，提交
    contractRawMoneySaveFun() {
      if(!this.files2?.length) {
        return this.$message.warning("请上传附件文件")
      }
      this.$refs.contractRawMoneySaveForm.validate((valid) => {
        if (valid) {
          this.contractRawMoneySaveForm.contractId = this.contractId;
          this.contractRawMoneySaveForm.rawId = this.QueryOneByidObject.rawId;
          this.contractRawMoneySaveForm.filePaths = JSON.stringify(this.files2);
          contractRawMoneySave(this.contractRawMoneySaveForm).then((res) => {
            if (res.code == 1001) {
              this.QueryOneByidFun();
            }
          });
        } else {
          return false;
        }
      });
    },
    //删除价格
    contractRawMoneyDeletesFun(d) {
      contractRawMoneyDeletes({ id: d }).then(() => {
        this.QueryOneByidObject.page = 1
        this.QueryOneByidFun();
      });
    },
    //协作单位-开户信息
    cooperativeUnitFun(d) {
      this.cooperativeUnit_Dialog = true;
      queryListsByPid({ supplierId: d }).then((res) => {
        this.cooperativeUnitArr = res.data;
      });
    },
    //协作单位组合
    queryListsByPidFun(d) {
      this.contractId = d.id;
      this.AllqueryListsByPid = true;
      console.log(d);
      queryListsByPid({ supplierId: d.supplierId }).then((res) => {
        this.queryListsByPidArr = res.data;
        // let obj = {
        //   id: d.supplierId,
        //   name: d.supplierName,
        // };
        // this.queryListsByPidArr.splice(0, 0, obj);
      });
    },
    //开户信息详情
    contractAccountGetDetailFun(d, index) {
      this.contractAccountGetDetailType = true;
      let obj = {
        contractId: this.contractId,
        pid: d,
        type: index == 1 ? "1" : "2",
      };
      contractAccountGetDetail(obj).then((res) => {
        this.contractAccountSaveForm = res.data;
        this.$refs.contractAccountSaveForm.resetFields();
      });
    },
    //开户信息保存
    contractAccountSaveFun() {
      this.$refs.contractAccountSaveForm.validate((valid) => {
        if (valid) {
          contractAccountSave(this.contractAccountSaveForm).then((res) => {
            if (res.code == 1001) {
              this.contractAccountGetDetailType = false;
            }
          });
        } else {
          return false;
        }
      });
    },
    //流程模式选择后重置
    processModelFun() {
      this.formDate.business = [];
    },
    //站点选择后重置
    stationsTypeFun() {
      this.formDate.business = [];
    },
    //重置表格-渲染
    reset() {
      this.headerNameType = false
      this.modifyType = false;
      this.formDate = {
        startDayendDay: [],
        id: "",
        contractTypeId: "1",
        contractType: "原物料",
        firstParty: "", //甲方
        supplierName: "", //供应商
        supplierTypeId: "", //供应商类型id
        userId: "",
        userName: "",
        firstSupplyName: "", //甲供合同
        clearingSource: "", //结算原
        clearingForm: "", //结算方式
        accessory: [], //附件
        cooperationClass: "合作等级", //甲方公司里面出来的
        cooperationClassId: "合作等级id", //甲方公司里面出来的
        business: [], //业务点1，2，3
        cplist: [], //添加：原物料列表
        firstSupplyId: "",
        settlementInterval: "", //结算周期，每多少月
      };
      this.cplistArr = [];
      this.businessCheckbox = [];
      this.files = [];
      this.files2 = [];
    },
    getLandedPriceFun(row) {
      console.log(JSON.parse(JSON.stringify(row)))
      this.thePrice_Dialog = true
      let json = {
        contractId: row.contractId,
        goodsId: row.rawId,
        money: row.factoryPrice
      }
      getLandedPrice(json).then((res) => {
        this.cplistArrList = res.data
      })
    },
    /**合同编号是否重复 */
    queryContractNumberFun() {
      queryContractNumber({ contractNumber: this.formDate.contractNumber, id: this.formDate.id }).then((res) => {
        if (res.code == 1001 && !res.data) {
          this.$message({
            message: '合同编号重复！',
            type: 'warning'
          });
          this.formDate.contractNumber = ''
        }
      })
    },
    /**单选列表打开 */
    ListChoiceTypeFun(index, id) {
      if (!this.formDate.firstPartyId) {
        this.$message({
          message: '请先选择甲方公司！',
          type: 'warning'
        });
        return
      }
      this.ListChoiceType = true
      this.ListChoiceDataIndex = index
      if (id) {
        this.ListChoiceRadio = id
        this.ListChoiceRadioCopy = id
      } else {
        this.ListChoiceRadio = ''
        this.ListChoiceRadioCopy = ''
      }
      this.checkName = ''
      this.checkTypeId = ''
      this.ListChoicePagingFun()
    },
    //单选选中
    ListChoiceFun(currentRow) {
      if (currentRow) {
        console.log(this.ListChoiceRadio + ';' + currentRow.id);
        let type = this.cplistArr.findIndex((res) => res.productId == currentRow.id)
        if (type == -1 || this.ListChoiceRadioCopy == currentRow.id) {
          this.ListChoiceRadio = currentRow.id
          this.ListChoiceRadioRow = currentRow
        } else {
          this.$message({
            message: '该选项已被选择！',
            type: 'warning'
          });
          setTimeout(() => {
            this.ListChoiceRadioRow = ''
          }, 100);
        }
      }
    },
    /**保存和校验不重复选中项 */
    ListChoiceAddFun() {
      //原物料选择后对应值【品牌，规格..】带入表格中
      this.cplistArr[this.ListChoiceDataIndex].productId = this.ListChoiceRadioRow.id;
      this.cplistArr[this.ListChoiceDataIndex].productName = this.ListChoiceRadioRow.name;
      this.cplistArr[this.ListChoiceDataIndex].specification = this.ListChoiceRadioRow.specification;
      this.cplistArr[this.ListChoiceDataIndex].specificationId = this.ListChoiceRadioRow.specificationId;
      this.cplistArr[this.ListChoiceDataIndex].brand = this.ListChoiceRadioRow.brand;
      this.cplistArr[this.ListChoiceDataIndex].brandId = this.ListChoiceRadioRow.brandId;
      this.cplistArr[this.ListChoiceDataIndex].rawId = this.ListChoiceRadioRow.rawId;
      this.cplistArr[this.ListChoiceDataIndex].barCode = this.ListChoiceRadioRow.barCode;
      this.cplistArr[this.ListChoiceDataIndex].originPlace = this.ListChoiceRadioRow.originPlace;
      this.ListChoiceType = false
    },
    /**分页查询列表 */
    ListChoicePagingFun(type) {
      if (!type) {
        this.ListChoicePaging.page = 1
        this.ListChoicePaging.name = this.checkName
        this.ListChoicePaging.typeId = this.checkTypeId
      }
      let json = [this.formDate.firstPartyId]
      this.ListChoicePaging.id = json.join(',')
      queryPageBycontractids(this.ListChoicePaging).then((res) => {
        this.ListChoiceData = res.data.data
        this.ListChoicePaging.total = res.data.totalRows
      })
    },
    sizeChange(value) {
      this.tableParam.pageSize = value;
      this.gettableData();
    },
  },
  filters: {
    //站点list表格中拼接展示
    stationsFun(arr) {
      if (arr) {
        let ket = JSON.parse(arr).map((res) => {
          return res.name;
        });
        return ket.join("、");
      } else {
        return "";
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.dialoginfo {
  .el-input,
  .el-select {
    width: 230px;
  }
}
.el-input,
.el-select {
  width: 240px;
}
.table_link {
  margin-left: 10px;
  color: $bg_color;
}
.table_link:hover {
  opacity: 0.8;
}
.form-title {
  font-size: 18px;
  margin: 10px 0;
}
.FZYguanKongYeWuDian {
  display: flex;
  > table {
    flex: none;
    width: 100px;
  }
  > div {
    flex: 1;
  }
}
</style>
<style lang="scss">
.contract {
  .FZYcheckbox {
    .el-checkbox {
      min-width: 155px;
      margin-right: 0px;
    }
  }
  .FZYform {
    padding-top: 0px !important;
    .el-cascader {
      width: 230px;
    }
    .el-form-item {
      min-width: 445px;
      .el-input,
      .el-select {
        width: 340px;
      }
      .hyyc {
        width: 310px;
        .el-input {
          width: 310px;
        }
      }
    }
    .zq {
      min-width: 500px;
      .el-input {
        width: 100px;
      }
      .el-input-number.is-without-controls .el-input__inner {
        width: 50px;
      }
    }
    .hyyc {
      width: 340px;
      .el-input {
        width: 340px;
      }
    }
  }
  .FZYform2 {
    .el-form-item__error {
      white-space: nowrap;
    }
  }
}
</style>